package com.hlg.xboot.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Description:日志类型</p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company: 中视数讯</p>
 * <p>Site: www.digi-zones.com</p>
 *
 * @author 杨信
 * @version 1.0
 * @date 2016/11/25
 */
public enum LogType {

    SYSTEM("后台管理", 1),
    API("API调用", 2);

    private String desc;
    private int value;

    LogType(String desc, int value) {
        this.desc = desc;
        this.value = value;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public static LogType getLogType(int value) {
        LogType logType = null;
        LogType[] enumAry = LogType.values();
        for (int i = 0; i < enumAry.length; i++) {
            if (enumAry[i].getValue() == value) {
                logType = enumAry[i];
                break;
            }
        }
        return logType;
    }

    public static List toList() {
        LogType[] ary = LogType.values();
        List list = new ArrayList();
        for (int i = 0; i < ary.length; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("value", String.valueOf(ary[i].getValue()));
            map.put("desc", ary[i].getDesc());
            list.add(map);
        }
        return list;
    }

    /**
     *日志类型记录的是中文 查询下拉选择value是desc中文值
     * @return
     */
    public static List toListType() {
        LogType[] ary = LogType.values();
        List list = new ArrayList();
        for (int i = 0; i < ary.length; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("value", ary[i].getDesc());
            map.put("desc", ary[i].getDesc());
            list.add(map);
        }
        return list;
    }
}
